package com.roy.workbench.bookmark.service;

import com.roy.workbench.bookmark.domain.Catalog;
import com.roy.workbench.bookmark.domain.CatalogRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;


/**
 * Created by elloxxn on 12/6/2017.
 */
@Service
public class CatalogService {
    @Autowired
    private CatalogRepository repository;

    public Page<Catalog> query(Pageable pageable) {
        return repository.findAll(pageable);
    }

    public Catalog findById(Long id) {
        return repository.findOne(id);
    }

    public Catalog save(Catalog catalog) {
        return repository.saveAndFlush(catalog);
    }

    public Catalog delete(Long id, Boolean needReturn) {
        if (needReturn) {
            Catalog catalog = repository.findOne(id);
            repository.delete(id);
            return catalog;
        }
        return null;
    }

}
